<template>
  <div class="member-order">
     <XtxTabs v-model="activeName" @tab-click="handleClick">
      <XtxTabsPanel v-for="item in orderStatus" :key="item.name" :label="item.label" :name="item.name">
      </XtxTabsPanel>
    </XtxTabs>
    <div class="order-list">
      <OrderItem v-for="item in list" :key="item.id" :order="item"></OrderItem>
    </div>
  </div>
</template>

<script>
import { reactive, ref, watch } from 'vue'
import { orderStatus } from '@/api/constants'
import { findOrderList } from '@/api/order'
import OrderItem from './components/order-item.vue'
export default {
  components: { OrderItem },
  name: 'MemberOrder',
  setup () {
    const activeName = ref('all')
    const handleClick = (val) => {
      // console.log(val, '自定义事件获取到的值')
      // 接口参数刚好和下标能对应起来，所以下标的值作为筛选参数
      params.orderState = val.index
    }
    const params = reactive({
      page: 1,
      pageSize: 10,
      orderState: 0
    })
    const list = ref([])
    watch(params, () => {
      findOrderList(params).then(({ result }) => {
        console.log(result)
        list.value = result.items
      })
    }, { immediate: true })
    return { activeName, handleClick, orderStatus, list }
  }
}
</script>

<style scoped lang="less">
.order-list {
  background: #fff;
  padding: 20px;
}

</style>
